define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {

            // $('.btn-add').data("area",["80%","100%"]);
            // $('.btn-edit').data("area",["80%","100%"]);

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'questionfeedback/index' + location.search,
                    //add_url: 'questionfeedback/add',
                    edit_url: 'questionfeedback/edit',
                    del_url: 'questionfeedback/del',
                    multi_url: 'questionfeedback/multi',
                    import_url: 'questionfeedback/import',
                    table: 'question_feedback',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible:true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'uid', title: __('会员编号')},
                        {field: 'course_id', title: __('课程编号')},
                        {field: 'course.name', title: __('课程名称')},
                        {field: 'question_id', title: __('题目编号')},
                        {field: 'content', title: __('Content'), operate: 'LIKE'},
                        {
                            field: 'status',
                            title: __('状态'),
                            formatter: Table.api.formatter.status,
                            searchList: {1: __('待处理'), 2: __('已处理')}
                        },
                        {field: 'create_time', title: __('反馈时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            buttons:[{
                                name: 'detail',
                                text: '题目管理',
                                title: '题目管理',
                                icon: 'fa fa-question-circle',
                                classname: 'btn btn-xs btn-primary btn-addtabs',
                                url: function (row) {
                                    return 'question/index/id/' + row.question_id;
                                },
                            }],
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            // table.on('post-body.bs.table',function () {
            //     $('.btn-editone').data("area",["80%","100%"]);
            // });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
            $('.view_question_id').click(function (){
               var question_id = $('.question_id').val();
                var url = 'question/index/id/'+question_id;
                var title = '题目管理';
                Backend.api.addtabs(url, title,'fa fa-question-circle fa-fw')
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
